define([
  'underscore',
  'backbone',
  './routes',
  './weiboapi',
  './view/app',
  './view/auth',
  './view/lists/menu',
  './collection/tasklists'
], function(_, Backbone, Routes, WeiboApi, AppView, AuthView, ListMenuView, TaskLists) {
  var App = function() {

    this.routes = new Routes();

    this.collections.lists = new TaskLists();

    this.views.app = new  AppView();
    this.views.app.render();

    this.views.auth = new AuthView(this);
    this.views.auth.render();
    //需在AppView render之后，否则取不到 el对象
    this.views.listMenu = new ListMenuView({collection: this.collections.lists});
  }

  App.prototype = {
    views: {},
    models: {},
    collections: {},
    connectWeiboApi: function() {
      var self = this;
      this.apiManager = new WeiboApi(this);
      this.apiManager.on('ready', function() {
        //collections fetch 回调函数触发渲染列表
        self.collections.lists.fetch({
          data: {
            count: 10
          },
          success: function() {
            Backbone.history.start();
            self.views.listMenu.render();
          }
        })
      });
      this.apiManager.loadWeiboApi();
    }
  }

  return App;
})